<template>
<div class="Registration">
    <!-- <el-row>

<el-col :span="24">

<el-card>

<el-form :model="searchForm" ref="form" label-width="80px" :inline="false" size="normal">

<div class="tab-row">
        <el-form-item label="区划名称:">
          <el-input v-model="searchForm.name"></el-input>
        </el-form-item>
        <el-form-item label="区划编号:">
          <el-input v-model="searchForm.areaId"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary">查询</el-button>
          <el-button>重置 </el-button>
          <el-button>展开 </el-button>
        </el-form-item>
      </div>

<div class="tab-row">
        <el-form-item label="行政级别:">
          <el-select
            value
            value-key
            placeholder="请选择(区、镇街、村居)"
            clearable
            filterable
             v-model="searchForm.level"
          >
            <el-option value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="父级行政区:">
          <el-select
            value
            value-key
            placeholder="请选择(区、镇街、村居)"
            clearable
            filterable
             v-model="searchForm.pareatArea"
          >
            <el-option value="1"></el-option>
          </el-select>
        </el-form-item>
      </div>

<div></div>

</el-form>

</el-card>

</el-col>

</el-row> -->

    <el-row>
        <el-col :span="24">
            <el-card>
                <el-button type="primary" style="" class="createtask" @click="auditMore()">批量审核</el-button>
                <!-- 当前页面的表单 -->
                <el-table :data="tableData" style="width: 100%" @selection-change="handleSelectionChange">

            <el-table-column
              prop="userId"
              type="selection"
              width="55"
            ></el-table-column>
                    <el-table-column prop="realName" label="姓名"> </el-table-column>
                    <!--      <el-table-column label="身份证号">
        <template slot-scope="scope">
          <span>{{ scope.row.registerCard | hiddenUid }}</span>
        </template>
      </el-table-column> -->

                    <el-table-column prop="registerCard" label="身份证">
                    </el-table-column>
                    <el-table-column prop="mobile" label="联系方式">
                    </el-table-column>
                    <el-table-column prop="administrativeName" label="辖区">
                    </el-table-column>
                    <el-table-column prop="administrativeName" label="用户类型">
                        <template slot-scope="scope">{{scope.row.userLevel=='4'?'镇管理员':'村管理员'}}</template>
                    </el-table-column>
                    <!-- <el-table-column prop="userAdministrativeCode" label="村居"> </el-table-column> -->
                    <el-table-column prop="registerAuditStatus" label="申请状态">
                        <template slot-scope="scope">
                            {{ userStatusCn(scope.row.status) }}
                        </template>

                        <!-- <template slot-scope="scope">{{scope.row.status=='1'?'通过':'不通过'}}</template> -->
                    </el-table-column>
                    <el-table-column label="操作" class-name="operation">
                        <template slot-scope="scope">
                            <el-link type="primary" @click="checkRegister(scope.row.userId)">审核</el-link>
                            <!-- <el-link

type="primary"

v-if="scope.row.registerAuditStatus === 0"

@click="checkRegister(scope.row.registerAuditStatus)"

>查看</el-link

  >

  <el-link

type="primary"

@click="checkRegister(scope.row.registerAuditStatus)"

v-else-if="scope.row.registerAuditStatus === 1"

>审核</el-link >

-->
                        </template>
                    </el-table-column>
                </el-table>

                <el-pagination background @size-change="sizeChange" @current-change="currentChange" :current-page="1" :page-sizes="[10, 20, 30, 40]" :page-size="10" layout="total, sizes, prev, pager, next, jumper" :total="total">
                </el-pagination>
            </el-card>
        </el-col>
    </el-row>
    <!-- 查看辖区人员的弹框 -->
    <el-dialog title="注册申请审核" :close-on-click-modal="false" :visible.sync="memberModalStatus" width="30%" :destroy-on-close="true">
        <main class="userdata">
            <!-- <p>采集人ID: {{ user.id }}</p> -->
            <p>申请人: {{ user.userName }}</p>
            <p>申请级别: {{ user.userLevel == 5 ? "村级" : "镇级" }}</p>
            <p>申请辖区: {{ user.userAdministrativeCode }}</p>
            <p>联系电话: {{ user.registerTele }}</p>
            <p>身份证号: {{ user.registerCard }}</p>
            <!-- <p>申请提交时间: {{ user.createTime }}</p> -->
        </main>
        <section v-if="modalMode == '0' || modalMode == '2'">
            <!-- <el-link type="primary" :underline="false">注册审核情况</el-link>
        <main>
          <p>审核时间: {{ user.registertime }}</p>
          <p>审核人: {{ user.name }}</p>
          <p>审核状态: {{ user.area }}</p>
          <p>审核批复: {{ user.phone }}</p>
        </main> -->
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="checkStatus">
                    {{ modalMode == "0" ? "审核通过" : "变更审核" }}
                </el-button>
            </span>
        </section>
        <section v-else-if="modalMode == '1'">
            <el-link type="primary" :underline="false">注册申请审核</el-link>
            <main>
                <el-form :model="registerForm" ref="registerForm" label-width="80px" :inline="false" :rules="rules" size="normal">
                    <el-form-item label="审核状态" prop="status">
                        <el-select value-key value placeholder clearable filterable v-model="registerForm.status">
                            <el-option value="1">通过</el-option>
                            <el-option value="2">不通过</el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="审核批复" prop="remind">
                        <el-input type="textarea" v-model="registerForm.remind"></el-input>
                    </el-form-item>
                </el-form>
            </main>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="onSubmit">提交</el-button>
            </span>
        </section>
    </el-dialog>
</div>
</template>

<script>
// import axios from 'axios';
import axios from "@/api/request.js";
export default {
    name: "Registration",
    data() {
        return {
            selectedData: [],
            pageNum: 1,
            size: 10,
            total: 0,
            registerForm: {
                status: "",
                remind: "",
            },
            searchForm: {
                name: "",
                level: "",
                parentArea: "",
                areaId: "",
            },
            rules: {
                status: [{
                    required: true,
                    message: "请选择是否通过",
                    trigger: "blur",
                }, ],
                remind: [{
                    required: true,
                    message: "请填写审核批复",
                    trigger: "change",
                }, ],
            },
            tableData: [],
            user: {
                userName: "张三",
            },
            totalNum: 60,
            modalMode: null,
            memberModalStatus: false,
        };
    },
    mounted() {
        this.list();
    },
    methods: {
        handleSelectionChange(val) {
            this.selectedData = val;
        },
        sizeChange(val) {
            console.log(val);
            this.size = val;
            this.list();
        },
        currentChange(val) {
            console.log(val);
            this.pageNum = val;
            this.list();
        },
        auditMore() {
            var val = this.selectedData;
            if (val.length <= 0) {
				this.$message.error("请勾选要批量审核的用户")
				return false;
			}
            this.$confirm("是否批量审核?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                })
                .then(() => {
                    if (val) {
                        val.forEach(function (item, index) {
                            console.log(item.userId);
                            //发送审核请求
                            axios
                                .post(`rbac/sysuser/regAuditStatus`, {
                                    params: {
                                        userIds: item.userId,
                                    },
                                })
                                .then((res) => {
                                    if (res && res.errorCode == "00000") {
                                        this.$message({
                                            type: 'success',
                                            message: '审核通过!'
                                        });
                                    }
                                });
                        });

                        setTimeout(() => {
                          this.list();
                        }, 1000);

                    }
                })
                .catch(() => {});
        },
        list() {
			let userLevel =JSON.parse(localStorage.getItem('userInfo')).userLevel;
			axios
                .get("/rbac/sysuser/list", {
                    params: {
                        pageNumber: this.pageNum,
                        pageSize: this.size,
                        userName: "",
                        status: 0,
						userLevel: userLevel
                    },
                })
                .then((response) => {
                    this.tableData = response.data.list;

                    this.total = response.data.total;
                });
        },
        checkRegister(id) {

            this.$confirm('是否通过审核, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {

                axios
                    .post(`rbac/sysuser/regAuditStatus`, {
                        params: {
                            userIds: id,
							status: 1,
							message:""
                        },
                    })
                    .then((res) => {
                        if (res && res.errorCode == "00000") {
                            this.$message({
                                type: 'success',
                                message: '审核通过!'
                            });
                            this.list();
                        }
                    });

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消审核'
                });
            });

        },

        checkStatus() {
            if (this.modalMode == 0) {
                this.memberModalStatus = false;
            } else if (this.modalMode == 2) {
                this.modalMode = 1;
            }
            //发送审核请求
            axios
                .post("baseinfo/api/v1.0/fishing/user/edit", {
                    params: {
                        id: this.user.id,
                        registerAuditStatus: 1,
                    },
                })
                .then((result) => {
                    this.list();
                    this.$message.success("审核完成");
                });
        },
        onSubmit() {
            this.$refs.registerForm.validate((valid) => {
                if (valid) {
                    this.memberModalStatus = false;
                } else {
                    return false;
                }
            });
        },
        userStatusCn(index) {
            var Status = {
                0: "待审核",
                1: "审核通过",
                2: "审核不通过",
            };

            return Status[index];
        },
    },

    created() {},
    filters: {
        hiddenUid(old) {
            let newone;
            //newone = old.slice(0, 12) + "******";
            return newone;
        },
    },
};
</script>

<style lang="scss">
.Registration {
    height: 100%;
    padding: 20px;
    background-color: #fff;

    .tab-row {
        display: flex;

        .el-form-item__label {
            white-space: nowrap;
        }

        .el-form-item__content {
            margin-right: 10px;
        }
    }

    .has-gutter {
        margin-top: 10px;

        .is-leaf {
            background: #fafafa;
            font-weight: 700;
            color: #000;
        }
    }

    .operation {
        span {
            margin: 0 5px;
        }
    }

    .el-pagination {
        display: flex;
        justify-content: flex-end;
        margin-top: 20px;
        text-align: right;
    }

    .el-dialog {
        .el-dialog__title {
            font-size: 16px;
            font-weight: 700;
        }

        .el-dialog__body {
            padding-top: 0;
        }

        .userdata {
            .username {
                margin-bottom: 25px;
                font-weight: 900;
                font-size: 20px;
                color: #000;
            }
        }

        p {
            color: #999;
            margin: 6px 0;
        }

        .el-link {
            margin: 5px 0;
        }

        .dialog-footer {
            display: flex;
            justify-content: center;
        }
    }

    .createtask {
        margin: 10px 0;
    }
}
</style>
